#include "Array2D.h"

CArray2D::CArray2D(int xsize, int ysize)
: xs(xsize), ys(ysize)
{
	if (xsize<=0 || ysize<=0)
		throw BadSize();

	arr2D = new int*[xsize];
	
	for(int i=0; i<xsize; i++)
		arr2D[i] = new int[ysize];
}

CArray2D::~CArray2D(void)
{
	for(int i=0; i<xs; i++)
		delete [] arr2D[i];

	delete [] arr2D;
}


int& CArray2D::operator() (int x, int y)
{
	if (x>=xs || y>=ys || x<0 || y<0)
		throw BoundsViolations();
	return arr2D[x][y];
}


const int& CArray2D::operator() (int x, int y) const
{
	if (x>=xs || y>=ys || x<0 || y<0)
		throw BoundsViolations();
	return arr2D[x][y];
}